//
//  ShowImageViewController.m
//  photographDemo
//
//  Created by 李胜军 on 2017/10/20.
//  Copyright © 2017年 李胜军. All rights reserved.
//

#import "ShowImageViewController.h"

#define kScreenBounds   [UIScreen mainScreen].bounds
#define kScreenWidth  kScreenBounds.size.width*1.0
#define kScreenHeight kScreenBounds.size.height*1.0

@interface ShowImageViewController ()
{
    UIImageView * imageV ;
}

@end

@implementation ShowImageViewController

-(void)setimageStr:(UIImage *)imageStr{
    
    _imageStr = imageStr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    imageV = [[UIImageView alloc]initWithFrame:self.view.bounds];
    imageV.image = _imageStr;
    imageV.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:imageV];
    
    
    UIButton * done = [[UIButton alloc]initWithFrame:CGRectMake(50, kScreenHeight-100, 100, 40)];
    [done addTarget:self action:@selector(doneClick) forControlEvents:UIControlEventTouchUpInside];
    [done setTitle:@"确定" forState:UIControlStateNormal];
    [done setBackgroundColor:[UIColor orangeColor]];
    [self.view addSubview:done];
    
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame = CGRectMake(kScreenWidth-140, kScreenHeight-100, 100, 40);
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    cancelBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [cancelBtn setBackgroundColor:[UIColor orangeColor]];
    [cancelBtn addTarget:self action:@selector(cancle) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:cancelBtn];
    
}


-(void)doneClick{
    
        //图片压缩
        NSData * data = UIImageJPEGRepresentation(_imageStr, 1);
        NSString *encodedImageStr = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];

        NSMutableDictionary * params = [NSMutableDictionary dictionary];
        params[@"base64Img"] = encodedImageStr;
        params[@"side"] = @"1";
        [HttpTool POST:ocridcard params:params success:^(NSURLSessionDataTask *task, id responseObject) {
            WYCLog(@"============%@",responseObject);

        } fail:^(NSURLSessionDataTask *task, NSError *error) {
            [SVProgressHUD showImage:[UIImage imageNamed:@""] status:Failed];
        }];

}

-(void)cancle{
    
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}





@end
